package com.example.windowdemo.threadpool;

import com.example.windowdemo.callback.WindowVisitorRunnable;
import com.example.windowdemo.window.vistor.WindowVisitor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: njb
 * @date: 2023/8/3 11:28
 * @desc:
 */
public class WindowVisitorThreadPool {
    private static final int THREAD_POOL_SIZE = 4;
    private ExecutorService executorService;

    public WindowVisitorThreadPool() {
        executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    }

    public void execute(WindowVisitorRunnable windowVisitorRunnable, WindowVisitor<?> window) {
        executorService.execute(() -> windowVisitorRunnable.run(window));
    }

    public void shutdown() {
        executorService.shutdown();
    }
}
